
#Title[P]
#Text[]
#Image[.]
#BackGround[User]
#Player[FREE]
#ScriptVersion[2]
script_enemy_main {
let csd = GetCurrentScriptDirectory;
    let imgBoss =csd ~ "..\lib/dot_aya.png"; 
	let imgEffect=csd ~ "..\img/effect_tiny.png";
	let imgBoss2 =csd ~ "..\lib/dot_aya2.png";
    // ʒu
    let xIni    = GetCenterX;
    let yIni    = GetClipMinY + 128;
	let Step2=false;
	let wIni=60;
let TimeCounter=90*60;
let StandardTimeCounter=TimeCounter;
    @Initialize {
	if(GetCommonDataDefault("ExclusiveBoss",false)==true)
	{
		BossTimer(TimeCounter);
	}
	else
	{
		SetTimer(TimeCounter/60);
	}
        SetLife(5200);
	InitializeAction();
	SetEnemyMarker(true);
	SetX(GetClipMinX-32);
	SetY(GetClipMinY+120);
        TMainGrobal;
    }

    @MainLoop {
	SetCommonData("BossX",GetX);
	SetCommonData("BossY",GetY);
	SetCommonData("BossLife",GetLife);
	BulletNum=GetEnemyShotCount;
	TimeCounter-=1;
        yield;
    }
//let windangle=0;
    @DrawLoop {
//DrawText(windangle,120,382,12,255);//NԂ̕\
	DrawBoss( imgBoss );
    }

    @Finalize {
	DeleteAllEnemyWithoutBoss;
	SetCommonData("BossX",GetX);
	SetCommonData("BossY",GetY);
	SetCommonData("BossLife",GetLife);
	DeleteEnemyShotToItem(ALL);
		if(!IsTimeOut)
		{
		SetCommonData("DeleteBulletNum",BulletNum);
		SetCommonData("DeleteBulletX",GetX);
		SetCommonData("DeleteBulletY",GetY);
		}

	SetCommonData("VanishSignal",false);
	SetCommonData("TimeBonus",TimeCounter/StandardTimeCounter);
	SetCommonData("BossRate",350000);
    }

    // C^XN
task TMainGrobal
{
	yield;
	GetDamege;
	OutDamageRateZero;
	Collision;
	//Lissajous(0,100,255);
	BossShadowAnimation(imgBoss2,0,0,100,255);
	standBy;
	alternative(GetCommonDataDefault("SELECTEDDIFFICULT","None"))
	case("Moderate")
	{
	shotM;
	}
	case("Extream")
	{
	shotE;
	}
	case("Apocalypse")
	{
	shotA;
	}
}

sub standBy//ʒu
{
	AppearEffect(285);
	SetAction(ACT_MOVE, 60);
//	windangle=atan2(GetClipMaxY-64-GetY,GetClipMaxX+128-GetX);
	SetMovePosition02(GetClipMaxX+128, GetClipMaxY-64,25);
	wait(15);
	SetCommonData("STAGE4BOSS",true);
	wait(15);
	wait(90);
	SetX(GetClipMinX-32);
	SetY(GetClipMaxY-120);
	SetAction(ACT_MOVE, 30);
//	windangle=atan2(GetClipMinY+96-GetY,GetClipMaxX+128-GetX);
	SetMovePosition02(GetClipMaxX+128, GetClipMinY+96,25);
	wait(15);
	wait(120);
	SetX(GetClipMinX+32);
	SetY(GetClipMinY-64);
	SetAction(ACT_MOVE, 60);
//	windangle=atan2( yIni-GetY,xIni-GetX);
	SetMovePosition03(xIni, yIni,20,5);
	wait(60);
	//summon;
	Concentration01(30);
	wait(30);
	//Concentration03(GetX,GetY,60,0,64,255);
}

task AppearEffect(w)
{
WindEffect;
loop(w)
{
	MomijiEffect;
	yield;
}
}

task WindEffect
{
		let R=255;let G=255; let B=255;
		let Angle=rand(0,360);
		let Speed=rand(0.2,0.4);
		let RotateAngle=rand(2,10);
		let Zangle=rand(0,360);
		let dir=rand_int(0,1)*2-1;
		let Scale=2.0;
		let Alpha=0;
		let AlphaMax=200;

		let obj = Obj_Create(OBJ_EFFECT);
		ObjEffect_SetTexture(obj, csd~"..\img\wind.png");
		ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
	//	ObjEffect_SetRenderState(obj, ADD); 
		ObjEffect_CreateVertex(obj, 4);
		ObjEffect_SetVertexXY(obj, 0, -320, -240);
		ObjEffect_SetVertexXY(obj, 1, 320,  -240);
		ObjEffect_SetVertexXY(obj, 2, 320, 240);
		ObjEffect_SetVertexXY(obj, 3,  -320,  240);
		
		ObjEffect_SetVertexUV(obj, 0,  0,  0);
		ObjEffect_SetVertexUV(obj, 1,  640, 0);
		ObjEffect_SetVertexUV(obj, 2, 640,  480);
		ObjEffect_SetVertexUV(obj, 3, 0, 480);
		ObjEffect_SetLayer(obj,3);
		ObjEffect_SetScale(obj, Scale,Scale);
		
		ascent(i in 0..4)
		{
		ObjEffect_SetVertexColor(obj,i,Alpha,R,G,B);
		}

		Obj_SetPosition(obj,GetCenterX,GetCenterY);

	//	if(GetCommonDataDefault("LightMode_SpecialEffect",0)==1){Obj_Delete(obj);return;}

		let EfX=0;
		let EfY=0;
		let WindSpeed=15;
		WindAngle;
		WindMomiji;
		WindMove;
		loop(360)
		{
			if(Alpha<AlphaMax)
			{
			Alpha+=AlphaMax/60;
			}
			ObjEffect_SetAngle(obj,0,0,Angle+90);
			ObjEffect_SetVertexUV(obj, 0,  0,  EfY+0);
			ObjEffect_SetVertexUV(obj, 1,  640*2, EfY+0);
			ObjEffect_SetVertexUV(obj, 2, 640*2,  EfY+480*2);
			ObjEffect_SetVertexUV(obj, 3, 0, EfY+480*2);
		ascent(i in 0..4)
		{
		ObjEffect_SetVertexColor(obj,i,Alpha,R,G,B);
		}
			EfY+=WindSpeed;
			yield;
		}
		loop(60)
		{
			if(Alpha>0)
			{
			Alpha-=AlphaMax/60;
			}
			ObjEffect_SetAngle(obj,0,0,Angle+90);
			ObjEffect_SetVertexUV(obj, 0,  0,  EfY+0);
			ObjEffect_SetVertexUV(obj, 1,  640*2, EfY+0);
			ObjEffect_SetVertexUV(obj, 2, 640*2,  EfY+480*2);
			ObjEffect_SetVertexUV(obj, 3, 0, EfY+480*2);
		ascent(i in 0..4)
		{
		ObjEffect_SetVertexColor(obj,i,Alpha,R,G,B);
		}
			EfY+=WindSpeed;
			yield;
		}
		Obj_Delete(obj);
		Alpha=0;

		task WindAngle
		{
			Angle=26;
			loop(145)
			{
				Angle+=(-23-26)/130;
				yield;
			}
			wait(15);
			loop(160)
			{
				Angle+=(50+23)/145;
				yield;
			}
			loop(45)
			{
				Angle+=(90-50)/45;
				yield;
			}
		}

	task WindMomiji
	{
		wait(5);
	let count=0;
		loop(340)
		{
			WindMomijiEffect(GetClipMinX,rand(GetClipMinY,GetClipMaxY));

			WindMomijiEffect(rand(GetClipMinX,GetClipMaxX),GetClipMinY-16);

			if(count%2==0){
			WindMomijiEffect(rand(GetClipMinX,GetClipMaxX),GetClipMaxY+16);
			}

			count+=1;
			yield;
		}
	}
		task WindMomijiEffect(x,y)
		{
		let R=255;let G=rand(0,165); let B=0;
		let MomijiAngle=Angle+rand(-10,10);
		let Speed=rand(WindSpeed/2,WindSpeed);
		let RotateAngleX=rand(2,10);
		let Xangle=rand(0,360);
		let RotateAngleY=rand(2,10);
		let Yangle=rand(0,360);
		let RotateAngle=rand(2,10);
		let Zangle=rand(0,360);
		let dir=rand_int(0,1)*2-1;
		let Scale=rand(0.5,1.0);
		let ScalePlus=rand(0.005,0.03);
		let WMAlpha=rand(100,150);

		let obj = Obj_Create(OBJ_EFFECT);
		ObjEffect_SetTexture(obj, imgEffect);
		ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
		ObjEffect_SetRenderState(obj, ADD); 
		ObjEffect_CreateVertex(obj, 4);
		ObjEffect_SetVertexXY(obj, 0, -16, -16);
		ObjEffect_SetVertexXY(obj, 1, 16,  -16);
		ObjEffect_SetVertexXY(obj, 2, 16, 16);
		ObjEffect_SetVertexXY(obj, 3,  -16,  16);
		
		ObjEffect_SetVertexUV(obj, 0,  0,  0);
		ObjEffect_SetVertexUV(obj, 1,  32, 0);
		ObjEffect_SetVertexUV(obj, 2, 32,  32);
		ObjEffect_SetVertexUV(obj, 3, 0, 32);
		ObjEffect_SetLayer(obj,rand_int(1,4));
		ObjEffect_SetScale(obj, Scale,Scale);
		
		ObjEffect_SetVertexColor(obj,0,WMAlpha,R,G,B);
		ObjEffect_SetVertexColor(obj,1,WMAlpha,R,G,B);
		ObjEffect_SetVertexColor(obj,2,WMAlpha,R,G,B);
		ObjEffect_SetVertexColor(obj,3,WMAlpha,R,G,B);

		Obj_SetPosition(obj,x,y);
		Obj_SetAngle(obj,Angle*0);
		Obj_SetSpeed(obj,Speed*0);


	//	if(GetCommonDataDefault("LightMode_SpecialEffect",0)==1){Obj_Delete(obj);return;}

		loop
		{
			Obj_SetPosition(obj,Obj_GetX(obj)+Speed*cos(Angle),Obj_GetY(obj)+Speed*sin(Angle));
			if(Obj_GetX(obj)<GetClipMinX-16 || Obj_GetX(obj)>GetClipMaxX+16 || Obj_GetY(obj)<GetClipMinY-16 || Obj_GetY(obj)>GetClipMaxY+16)
			{break;}
			ObjEffect_SetAngle(obj,0,0,Zangle);
		//	ObjEffect_SetAngle(obj,Xangle,Yangle,Zangle);
			ObjEffect_SetScale(obj, Scale,Scale);
			Zangle+=RotateAngle*dir;
		//	Xangle+=RotateAngleX*dir;
		//	Yangle+=RotateAngleY*dir;
			if(Scale<1.5)
			{
				Scale+=ScalePlus;
			}
			else{		Scale-=ScalePlus;}
			yield;
		}
		Obj_Delete(obj);
		}


		task WindMove
		{
		let Intensity=0;
		loop(420)
		{
			SetPlayerX(GetPlayerX+Intensity*cos(Angle));
			SetPlayerY(GetPlayerY+Intensity*sin(Angle));
			Intensity=Alpha/200*2;
			//if(Intensity==0){break;}
			yield;
		}

		}
}

task MomijiEffect//gt̐ݒ
{
		let R=255;let G=rand(0,165); let B=0;
		let Angle=rand(0,360);
		let Speed=rand(0.2,0.4);
		let RotateAngle=rand(2,10);
		let Zangle=rand(0,360);
		let dir=rand_int(0,1)*2-1;
		let Scale=1.0;
		let Alpha=150;

		let obj = Obj_Create(OBJ_EFFECT);
		ObjEffect_SetTexture(obj, imgEffect);
		ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
		ObjEffect_SetRenderState(obj, ADD); 
		ObjEffect_CreateVertex(obj, 4);
		ObjEffect_SetVertexXY(obj, 0, -16, -16);
		ObjEffect_SetVertexXY(obj, 1, 16,  -16);
		ObjEffect_SetVertexXY(obj, 2, 16, 16);
		ObjEffect_SetVertexXY(obj, 3,  -16,  16);
		
		ObjEffect_SetVertexUV(obj, 0,  0,  0);
		ObjEffect_SetVertexUV(obj, 1,  32, 0);
		ObjEffect_SetVertexUV(obj, 2, 32,  32);
		ObjEffect_SetVertexUV(obj, 3, 0, 32);
		ObjEffect_SetLayer(obj,4);
		ObjEffect_SetScale(obj, Scale,Scale);
		
		ObjEffect_SetVertexColor(obj,0,Alpha,R,G,B);
		ObjEffect_SetVertexColor(obj,1,Alpha,R,G,B);
		ObjEffect_SetVertexColor(obj,2,Alpha,R,G,B);
		ObjEffect_SetVertexColor(obj,3,Alpha,R,G,B);

		Obj_SetPosition(obj,GetX+10*cos(Angle),GetY+10*sin(Angle));
		Obj_SetAngle(obj,Angle*0);
		Obj_SetSpeed(obj,Speed*0);


		if(GetCommonDataDefault("LightMode_SpecialEffect",0)==1){Obj_Delete(obj);return;}

		loop(30)
		{
			Obj_SetPosition(obj,Obj_GetX(obj)+Speed*cos(Angle),Obj_GetY(obj)+Speed*sin(Angle));
			ObjEffect_SetAngle(obj,0,0,Zangle);
			ObjEffect_SetScale(obj, Scale,Scale);
			Zangle+=RotateAngle*dir;
			Scale-=1.0/30;
			yield;
		}
		Obj_Delete(obj);
}

task Collision
{
	loop(315)
	{
        SetCollisionA(GetX, GetY, 48);
	yield;
	}

	loop
	{
        SetCollisionA(GetX, GetY, 48);
        MSDSetCollisionB(GetX, GetY, 16);
	yield;
	}
}



task summon
{
        CreateEnemyFromScript("Familiar", GetX, GetY,
                              0, 0, 1);
        CreateEnemyFromScript("Familiar", GetX, GetY,
                              0, 0, -1);
}

task TMove
{
loop
{
//	SetMovePosition03(GetX+rand(-10,10), GetY+rand(-10,10), 20,5);
	wait(60);
}
}


task shotM
{

let looptime=0;
let X=GetClipMinX;
let Y=GetCenterY;
loop
{
	let Radius=0;
	let angle=rand(0,360);
	let speed=4.5;
	let speed2=4.5;
	SetAction(ACT_SHOT_A, 300);
	loop(30)
	{
		ascent(i in 0..4)
		{
		Shot1(GetX+Radius*cos(angle+i*90),GetY+Radius*sin(angle+i*90),speed,angle+i*90,9,85,5);
		Shot1(GetX+Radius*cos(angle+i*90+45),GetY+Radius*sin(angle+i*90+45),speed2,angle+i*90+45,9,86,5);
		}
		wait(10);
		angle+=rand(15,20);
		Radius+=1;
	}
	wait(60);
	let X=rand(GetCenterX+96,GetCenterX+160);
	let Y=rand(GetCenterY-64,GetCenterX-96);
	SetAction(ACT_MOVE, 30);
	SetMovePosition02(X, Y,30);
	Shot3;
	wait(60);
	let X=rand(GetCenterX-96,GetCenterX-160);
	let Y=rand(GetCenterY-64,GetCenterX-96);
	SetAction(ACT_MOVE, 30);
	SetMovePosition02(X, Y,30);
	Shot2;
	wait(60);
	let X=rand(GetCenterX+96,GetCenterX+160);
	let Y=rand(GetCenterY-64,GetCenterX-96);
	SetAction(ACT_MOVE, 30);
	SetMovePosition02(X, Y,30);
	Shot3;
	wait(60);
	let Y=rand(GetCenterY-96,GetCenterX-128);
	SetAction(ACT_MOVE, 15);
	SetMovePosition02(GetCenterX, Y,15);
	wait(15);
	SetAction(ACT_SHOT_B, 180);
	Shot4;
	wait(180);
	SetAction(ACT_MOVE, 30);
	SetMovePosition03(xIni, yIni, 20,5);
	wait(60);
	SetAction(ACT_SHOT_B, 60);
	summon;
	wait(450);
	Radius=0;
	angle=rand(0,360);
	SetAction(ACT_SHOT_A, 300);
	loop(30)
	{
		ascent(i in 0..4)
		{
		Shot1(GetX+Radius*cos(angle+i*90),GetY+Radius*sin(angle+i*90),speed,angle+i*90,9,85,5);
		Shot1(GetX+Radius*cos(angle+i*90+45),GetY+Radius*sin(angle+i*90+45),speed2,angle+i*90+45,9,86,5);
		}
		wait(10);
		angle+=rand(15,20);
		Radius+=1;
	}
	wait(30);
	Shot5;
	loop(3)
	{
		wait(45);
		Shot1(GetX,GetY,speed,GetAngleToPlayer,15,85,10);
		wait(60);
		Shot1(GetX,GetY,speed,GetAngleToPlayer,15,85,10);
		wait(15);
		SetAction(ACT_MOVE, 15);
		SetMovePosition02(GetPlayerX, GetY,15);
	}
		wait(45);
		Shot1(GetX,GetY,speed,GetAngleToPlayer,15,85,10);
		wait(60);
		Shot1(GetX,GetY,speed,GetAngleToPlayer,15,85,10);
		wait(15);
	wait(60);
	SetAction(ACT_MOVE, 30);
	SetMovePosition03(xIni, yIni, 20,5);
	wait(60);


			function Shot1(let sx,let sy,let speed,let angle,let wide,let gra,let delay)
			{
				let way=9;
				ascent(i in -(way-1)/2..(way+1)/2)
				{
					CreateShot01(sx,sy,speed/((1.05)^absolute(i)),angle+wide/(way-1)*i,gra,delay);
				}
			}

			task Shot2
			{
			loop(15)
			{
				ascent(i in 0..36)
				{
				let angle=GetAngleToPlayer;
				CreateShotA(0,GetX,GetY,0);
				SetShotDataA(0,0,9,angle+i*10,12,0,0,81);
				SetShotDataA(0,30,7,angle+i*10,0,0,0,81);
				FireShot(0);
				}
				wait(2);
			}
			}

			task Shot3
			{
			loop(15)
			{
				ascent(i in 0..36)
				{
				let angle=GetAngleToPlayer;
				CreateShotA(0,GetX,GetY,0);
				SetShotDataA(0,0,9,angle+i*10+5,12,0,0,85);
				SetShotDataA(0,30,7,angle+i*10+5,0,0,0,85);
				FireShot(0);
				}
				wait(2);
			}
			}

			task Shot4
			{
			let angle=GetAngleToPlayer;
			loop(20)
			{
				ascent(i in 0..36)
				{
					CreateShot01(GetX,GetY,8,angle+i*10,105,5);
				}
				wait(3);
			}
			let dir=-1;
			if(angle<=90){dir=1;}
			loop(20)
			{
				ascent(i in 0..36)
				{
					CreateShot01(GetX,GetY,8,angle+i*10,105,5);
				}
				angle+=dir;
				wait(3);
			}
			}

			task Shot5
			{
				let angle=75;
			loop(5)
			{
				loop(15)
				{
					loop(2)
					{
					CreateShot01(rand(GetClipMinX-16,GetClipMaxX+16),GetClipMinY,rand(2.75,3.25),angle+rand(-2,2),45,15);
					}
					wait(3);
					angle+=2;
				}
				loop(15)
				{
					loop(2)
					{
					CreateShot01(rand(GetClipMinX-16,GetClipMaxX+16),GetClipMinY,rand(2.75,3.25),angle+rand(-2,2),45,15);
					}
					wait(3);
					angle-=2;
				}
			}
			}

	task summon
	{
     		CreateEnemyFromScript("Familiar", GetX, GetY,
       	                       0, 0, 1);
       		CreateEnemyFromScript("Familiar", GetX, GetY,
                              0, 0, -1);
	}

}


}
/////////////////////////////////////////////////////////////////////////////
task shotE
{
let looptime=0;
wait(30);
loop
{

	let angle=GetAngleToPlayer;
	let speed=5;
	let way=8;
	SetAction(ACT_SHOT_A, 90);
	ascent(i in 0..way)
	{
		PondeShot(GetX,GetY,speed,angle+i*360/way,9,5);
	}
	wait(30);
	ascent(i in 0..way)
	{
		PondeShot(GetX,GetY,speed,angle+i*360/way+180/way,9,5);
	}
	wait(30);
	ascent(i in 0..way)
	{
		PondeShot(GetX,GetY,speed,angle+i*360/way,9,5);
	}
	wait(240);
	let X=rand(GetCenterX+96,GetCenterX+160);
	let Y=rand(GetCenterY-64,GetCenterX-96);
	SetAction(ACT_MOVE, 30);
	SetMovePosition02(X, Y,30);
	Shot3;
	wait(60);
	let X=rand(GetCenterX-96,GetCenterX-160);
	let Y=rand(GetCenterY-64,GetCenterX-96);
	SetAction(ACT_MOVE, 30);
	SetMovePosition02(X, Y,30);
	wait(60);
	let X=rand(GetCenterX+96,GetCenterX+160);
	let Y=rand(GetCenterY-64,GetCenterX-96);
	SetAction(ACT_MOVE, 30);
	SetMovePosition02(X, Y,30);
	wait(60);
	let Y=rand(GetCenterY-96,GetCenterX-128);
	SetAction(ACT_MOVE, 15);
	SetMovePosition02(GetCenterX, Y,15);
	wait(75);
	SetAction(ACT_SHOT_A, 90);
	Shot4;
	wait(180);
	SetAction(ACT_MOVE, 30);
	SetMovePosition03(xIni, yIni, 20,5);
	wait(60);
	SetAction(ACT_SHOT_B, 60);
	summon;
	wait(450);

	let angle=GetAngleToPlayer;
	let speed=5;
	let way=8;
	SetAction(ACT_SHOT_A, 90);
	ascent(i in 0..way)
	{
		PondeShot(GetX,GetY,speed,angle+i*360/way,9,5);
	}
	wait(30);
	ascent(i in 0..way)
	{
		PondeShot(GetX,GetY,speed,angle+i*360/way+180/way,9,5);
	}
	wait(30);
	ascent(i in 0..way)
	{
		PondeShot(GetX,GetY,speed,angle+i*360/way,9,5);
	}
	wait(240);
	Shot5;
	loop(3)
	{
		wait(45);
		ExPondeShot(GetX, GetY,3.5,GetAngleToPlayer, 15, 10);
		wait(60);
		ExPondeShot(GetX, GetY,3.5,GetAngleToPlayer, 15, 10);
		wait(15);
		SetAction(ACT_MOVE, 15);
		SetMovePosition02(GetPlayerX, GetY,15);
	}
		wait(45);
		ExPondeShot(GetX, GetY,3.5,GetAngleToPlayer, 15, 10);
		wait(60);
		ExPondeShot(GetX, GetY,3.5,GetAngleToPlayer, 15, 10);
		wait(15);
	wait(60);
	SetAction(ACT_MOVE, 30);
	SetMovePosition03(xIni, yIni, 20,5);
	wait(60);


}

			function Shot2
			{
			loop(15)
			{
				ascent(i in 0..36)
				{
				let angle=GetAngleToPlayer;
				CreateShotA(0,GetX,GetY,0);
				SetShotDataA(0,0,5,angle+i*10,12,0,0,81);
				SetShotDataA(0,30,7,angle+i*10,0,0,0,81);
				FireShot(0);
				}
				wait(2);
			}
			}

			task Shot3
			{
			loop(15)
			{
				let angle=rand(0,360);
				ascent(i in 0..15)
				{
				CreateShotA(0,GetX,GetY,0);
				SetShotDataA(0,0,0,angle+i*24,0,0.025,4.5,81);
				FireShot(0);
				}
				wait(2);
			}
			wait(30);
			loop(15)
			{
				let angle=rand(0,360);
				ascent(i in 0..15)
				{
				CreateShotA(0,GetX,GetY,0);
				SetShotDataA(0,0,0,angle+i*24,0,0.025,4.5,84);
				FireShot(0);
				}
				wait(2);
			}
			wait(30);
			loop(15)
			{
				let angle=rand(0,360);
				ascent(i in 0..15)
				{
				CreateShotA(0,GetX,GetY,0);
				SetShotDataA(0,0,0,angle+i*24,0,0.025,4.5,81);
				FireShot(0);
				}
				wait(2);
			}
			}

			task Shot5
			{
			let angle=255;
			wait(30);
			loop(5)
			{
				loop(15)
				{
					loop(2)
					{
					CreateShot01(rand(GetClipMinX-32,GetClipMaxX+32),GetClipMaxY,rand(1.75,2.25),angle+rand(-2,2),45,20);
					}
					wait(3);
					angle+=2;
				}
				loop(15)
				{
					loop(2)
					{
					CreateShot01(rand(GetClipMinX-32,GetClipMaxX+32),GetClipMaxY,rand(1.75,2.25),angle+rand(-2,2),45,20);
					}
					wait(3);
					angle-=2;
				}
			}

			}

			function Shot4
			{
				let angle=rand(0,360);
				ascent( i in 0..15)
				{
				ExPondeShot(GetX, GetY,4,angle+i*24, 15, 10);
				}
				wait(30);
				ascent( i in 0..15)
				{
				ExPondeShot(GetX, GetY,4,angle+i*24+12, 15, 10);
				}
				wait(30);
				let angle=GetAngleToPlayer;
				ascent( i in 0..15)
				{
				ExPondeShot(GetX, GetY,4,angle+i*24, 15, 10);
				}

			}

task ExPondeShot(let x, let y, let speed,let angle, let graphic, let delay)
{
	let count=0;
	let count1=0;
	let obj = Obj_Create(OBJ_SHOT);
	Obj_SetPosition(obj, x, y);
	Obj_SetSpeed(obj, speed);
	Obj_SetAngle(obj, angle);
	ObjShot_SetGraphic(obj, graphic);
	ObjShot_SetDelay(obj, delay);
	Obj_SetAlpha(obj,0);
	Obj_SetCollisionToPlayer(obj,false);
	Obj_SetAutoDelete(obj,false);
	ObjShot_SetBombResist(obj,true);
	ascent(i in 0..15)
	{
		Exshot(obj,speed,angle,i*24);
	}
	loop(300)
	{
		yield;
    	}
	Obj_Delete(obj);
}

task Exshot(Pobj,speed,angle,SetAngle)
{
	let count=0;
	let r=0;
	let Radius=50;
	let graphic=12;
	let obj = Obj_Create(OBJ_SHOT);
	Obj_SetPosition(obj, Obj_GetX(Pobj)+Radius*cos(SetAngle), Obj_GetY(Pobj)+Radius*sin(SetAngle));
	Obj_SetSpeed(obj, Obj_GetSpeed(Pobj));
	Obj_SetAngle(obj, angle);
	ObjShot_SetGraphic(obj, graphic);
	ObjShot_SetDelay(obj, 5);
	while(!Obj_BeDeleted(obj))
	{
		Obj_SetPosition(obj, Obj_GetX(Pobj)+r*cos(SetAngle), Obj_GetY(Pobj)+r*sin(SetAngle));
		r+=0.75;
		yield;
    	}
}

task PondeShot(let x, let y, let speed,let angle, let graphic, let delay)
{
	let count=0;
	let count1=0;
	let obj = Obj_Create(OBJ_SHOT);
	Obj_SetPosition(obj, x, y);
	Obj_SetSpeed(obj, speed);
	Obj_SetAngle(obj, angle);
	ObjShot_SetGraphic(obj, graphic);
	ObjShot_SetDelay(obj, delay);
	Obj_SetAlpha(obj,0);
	Obj_SetCollisionToPlayer(obj,false);
	Obj_SetAutoDelete(obj,false);
	ObjShot_SetBombResist(obj,true);
	let ra=rand(0,360);
	ascent(i in 0..12)
	{
		shot(obj,speed,angle,i*30+ra);
	}
	while(!Obj_BeDeleted(obj) && count==0)
	{
		if(Obj_GetX(obj)<GetClipMinX && count==0)//[ł̋
		{
			Obj_SetX(obj, GetClipMinX*2-Obj_GetX(obj));
			Obj_SetAngle(obj,180-angle);
			count=1;
        	}
		if(Obj_GetX(obj)>GetClipMaxX && count==0)//E[ł̋
		{
			Obj_SetX(obj, GetClipMaxX*2-Obj_GetX(obj));
			Obj_SetAngle(obj,180-angle);
			count=1;
        	}
		if(Obj_GetY(obj)<GetClipMinY && count==0)//[ł̋
		{
			Obj_SetY(obj, GetClipMinY*2-Obj_GetY(obj));
			Obj_SetAngle(obj,360-angle);
			count=1;
        	}
		yield;
    	}
	while(!Obj_BeDeleted(obj) && speed>0)
	{
		speed-=0.1;
		Obj_SetSpeed(obj, speed);
		yield;
    	}
	Obj_Delete(obj);
}

task shot(Pobj,speed,angle,SetAngle)
{
	let count=0;
	let r=0;
	let Radius=50;
	let graphic=12;
	let obj = Obj_Create(OBJ_SHOT);
	Obj_SetPosition(obj, Obj_GetX(Pobj)+Radius*cos(SetAngle), Obj_GetY(Pobj)+Radius*sin(SetAngle));
	Obj_SetSpeed(obj, speed);
	Obj_SetAngle(obj, angle);
	ObjShot_SetGraphic(obj, graphic);
	ObjShot_SetDelay(obj, 5);
	while(!Obj_BeDeleted(obj) && !Obj_BeDeleted(Pobj))
	{
		if(Obj_GetX(obj)<GetClipMinX && count==0)//[ł̋
		{
			Obj_SetX(obj, GetClipMinX*2-Obj_GetX(obj));
			Obj_SetAngle(obj,180-angle);
			count=1;
        	}
		if(Obj_GetX(obj)>GetClipMaxX && count==0)//E[ł̋
		{
			Obj_SetX(obj, GetClipMaxX*2-Obj_GetX(obj));
			Obj_SetAngle(obj,180-angle);
			count=1;
        	}
		if(Obj_GetY(obj)<GetClipMinY && count==0)//[ł̋
		{
			Obj_SetY(obj, GetClipMinY*2-Obj_GetY(obj));
			Obj_SetAngle(obj,360-angle);
			count=1;
        	}
		Obj_SetSpeed(obj, Obj_GetSpeed(Pobj));
		yield;
    	}
	angle=rand(85,95);
	speed=0;
	let Sspeed=rand(2,3);
	ObjShot_SetGraphic(obj, 15);
	while(!Obj_BeDeleted(obj))
	{
		if(speed<Sspeed)
		{speed+=0.02;}
		Obj_SetAngle(obj, angle);
		Obj_SetSpeed(obj,speed);
		yield;
    	}
}

}
//////////////////////////////////////////////////////////////////////
task shotA
{
wait(30);
loop
{
	SpellDraw(26,300);
	let angle=rand(0,360);
	let dir=rand_int(0,1)*2-1;
	SetAction(ACT_SHOT_A, 180);
	loop(12)
	{
	ascent(i in 0..10)
	{
		KonohaShot(GetX,GetY,4,angle+i*36,45,1);
		KonohaShot(GetX,GetY,3,angle+i*36,45,-1);
		KonohaShot(GetX,GetY,2,angle+i*36,45,1);
	}
		wait(5);
	}
	wait(30);
	loop(12)
	{
	ascent(i in 0..10)
	{
		KonohaShot(GetX,GetY,4,angle+i*36,44,-1);
		KonohaShot(GetX,GetY,3,angle+i*36,44,1);
		KonohaShot(GetX,GetY,2,angle+i*36,44,-1);
	}
		wait(5);
	}	
	wait(150);
	let Y=rand(GetCenterY-64,GetCenterY-96);
	SetAction(ACT_MOVE, 15);
	SetMovePosition02(GetClipMaxX, Y,15);
	wait(15);
	Shot1;
	let Y=rand(GetCenterY-160,GetCenterY-128);
	SetAction(ACT_MOVE, 15);
	SetMovePosition02(GetClipMinX, Y,15);
	wait(15);
	Shot1;
	let Y=rand(GetCenterY-128,GetCenterY-96);
	SetAction(ACT_MOVE, 15);
	SetMovePosition02(GetClipMaxX, Y,15);
	wait(15);
	Shot1;
	let Y=rand(GetCenterY-96,GetCenterY-64);
	SetAction(ACT_MOVE, 15);
	SetMovePosition02(GetClipMinX, Y,15);
	wait(15);
	let Y=rand(GetCenterY-64,GetCenterY-32);
	SetAction(ACT_MOVE, 15);
	SetMovePosition02(GetClipMaxX, Y,15);
	wait(15);
	Shot1;
	let Y=rand(GetCenterY-32,GetCenterY-0);
	SetAction(ACT_MOVE, 15);
	SetMovePosition02(GetClipMinX, Y,15);
	wait(15);
	Shot1;
	let Y=rand(GetCenterY+0,GetCenterY+32);
	SetAction(ACT_MOVE, 15);
	SetMovePosition02(GetClipMaxX, Y,15);
	wait(15);
	Shot1;
	let Y=rand(GetCenterY+64,GetCenterY+96);
	SetAction(ACT_MOVE, 15);
	SetMovePosition02(GetClipMinX, Y,15);
	wait(15);
	Shot1;
	let Y=rand(GetCenterY+96,GetCenterY+128);
	SetAction(ACT_MOVE, 15);
	SetMovePosition02(GetClipMaxX, Y,15);
	wait(15);
	Shot1;
	let Y=rand(GetCenterY+96,GetCenterY+128);
	SetAction(ACT_MOVE, 15);
	SetMovePosition02(GetClipMinX, Y,15);
	wait(15);
	Shot1;
	let Y=rand(GetCenterY+128,GetCenterY+160);
	SetAction(ACT_MOVE, 15);
	SetMovePosition02(GetClipMaxX, Y,15);
	wait(15);
	Shot1;
	SetAction(ACT_MOVE, 15);
	SetMovePosition02(GetCenterX, GetCenterY-48,15);
	wait(15);
	SetAction(ACT_SHOT_B, 180);
	Shot4;
	wait(180);
	SetAction(ACT_MOVE, 30);
	SetMovePosition03(xIni, yIni, 20,5);
	wait(60);
	SetAction(ACT_SHOT_B, 60);
	summon;
	wait(450);
	let angle=rand(0,360);
	let dir=rand_int(0,1)*2-1;
	SpellDraw(26,300);
	SetAction(ACT_SHOT_A, 180);
	loop(12)
	{
	ascent(i in 0..12)
	{
		KonohaShot(GetX,GetY,4,angle+i*30,45,1);
		KonohaShot(GetX,GetY,3,angle+i*30,45,-1);
		KonohaShot(GetX,GetY,2,angle+i*30,45,1);
	}
		wait(5);
	}
	wait(30);
	loop(12)
	{
	ascent(i in 0..12)
	{
		KonohaShot(GetX,GetY,4,angle+i*30,44,-1);
		KonohaShot(GetX,GetY,3,angle+i*30,44,1);
		KonohaShot(GetX,GetY,2,angle+i*30,44,-1);
	}
		wait(5);
	}	
	wait(180);
	Shot5;
	let speed=4;
	loop(3)
	{
		wait(45);
		Shot6(GetX,GetY,speed,GetAngleToPlayer,15,85,10);
		wait(60);
		Shot6(GetX,GetY,speed,GetAngleToPlayer,15,85,10);
		wait(15);
		SetAction(ACT_MOVE, 15);
		SetMovePosition02(GetPlayerX, GetY,15);
	}
		wait(45);
		Shot6(GetX,GetY,speed,GetAngleToPlayer,15,85,10);
		wait(60);
		Shot6(GetX,GetY,speed,GetAngleToPlayer,15,85,10);
		wait(15);
	wait(60);
	SetAction(ACT_MOVE, 30);
	SetMovePosition03(xIni, yIni, 20,5);
	wait(60);
}

function Shot1
{
	let angle=rand(0,360);
	ascent(i in 0..30)
	{
		CreateShot01(GetX,GetY,2.5,angle+i*12,86,0);
	}
}

	function Shot4
	{
	let angle=rand(0,360);
	let speed=8;
	loop(120)
	{

	CreateShotA(0,GetX,GetY,0);
	SetShotDataA(0,0,speed,angle,0,-speed/30,0,81);
	SetShotDirectionType(PLAYER);
	SetShotDataA(0,30,NULL,0,0,0.15,10,81);
	SetShotDirectionType(ABSOLUTE);
	FireShot(0);
	CreateShotA(0,GetX,GetY,0);
	SetShotDataA(0,0,speed,angle+180,0,-speed/30,0,81);
	SetShotDirectionType(PLAYER);
	SetShotDataA(0,30,NULL,0,0,0.2,20,81);
	SetShotDirectionType(ABSOLUTE);
	FireShot(0);
	angle+=12;
	speed+=0.08;
	yield;
	}


	}

			task Shot5
			{
			let angle=345;
			wait(30);
			loop(5)
			{
				loop(9)
				{
					loop(3)
					{
					CreateShot01(GetClipMinX,rand(GetClipMinY-32,GetClipMaxY+32),rand(1.75,2.25),angle+rand(-2,2),45,20);
					CreateShot01(GetClipMaxX,rand(GetClipMinY-32,GetClipMaxY+32),rand(1.75,2.25),180+angle+rand(-2,2),45,20);
					}
					wait(5);
					angle+=2;
				}
				loop(9)
				{
					loop(3)
					{
					CreateShot01(GetClipMinX,rand(GetClipMinY-32,GetClipMaxY+32),rand(1.75,2.25),angle+rand(-2,2),45,20);
					CreateShot01(GetClipMaxX,rand(GetClipMinY-32,GetClipMaxY+32),rand(1.75,2.25),180+angle+rand(-2,2),45,20);
					}
					wait(5);
					angle-=2;
				}
			}

			}

			function Shot6(let sx,let sy,let speed,let angle,let wide,let gra,let delay)
			{
				ascent(i in -5..6)
				{
					ascent(j in 0..6)
					{
					CreateShot01(sx,sy,speed+j*0.2,angle+i*2,gra,delay);
					}
				}
			}

function KonohaShot(x,y,speed,angle,gra,dir)
{
	CreateShotA(0,x,y,0);
	SetShotDataA(0,0,speed,angle,3*dir,0.00,0,gra);
	SetShotDataA(0,60,speed,NULL,1.5*dir,0.00,0,gra);
	SetShotDataA(0,120,speed,angle+270*dir+rand(-15,15),0,0.00,0,gra);
	FireShot(0);
}

task shot(x,y,angle,pangle,dir)
{
	//let pangle=30;
	let speed=0;
	let count=0;
	let Radius1=0;
	let Radius2=0;
	let RadiusAngle=0;
	let graphic=12;
	let obj = Obj_Create(OBJ_SHOT);
	//Obj_SetPosition(obj, x+Radius*cos(angle), y+Radius*sin(angle));
	Obj_SetSpeed(obj, speed);
	Obj_SetAngle(obj, angle);
	ObjShot_SetGraphic(obj, graphic);
	ObjShot_SetDelay(obj, 5);
	Obj_SetAlpha(obj,0);
	OpShot(obj);
	while(!Obj_BeDeleted(obj))
	{
		Obj_SetX(obj,x+Radius1*cos(pangle)*cos(angle)-Radius2*sin(pangle)*sin(angle));
		Obj_SetY(obj,y+Radius1*sin(pangle)*cos(angle)+Radius2*cos(pangle)*sin(angle));
	//	Obj_SetPosition(obj, x+Radius1*cos(angle), y+Radius1*sin(angle));
		if(Radius1<100)
		{
			//Radius1+=1;
			//Radius2+=0.5;
		}
		Radius1=75+50*sin(RadiusAngle);
		Radius2=50+25*sin(RadiusAngle);
		RadiusAngle+=0.6;
		pangle+=3*dir;
		angle+=3*dir;
		//if(count>=300){break;}
		count+=1;
		yield;
    	}
	
	task OpShot(obj)
	{
		while(!Obj_BeDeleted(obj))
		{
				CreateShotA(0,Obj_GetX(obj),Obj_GetY(obj),0);
				SetShotDataA(0,0,0,atan2(GetY-Obj_GetY(obj),GetX-Obj_GetX(obj))+180,0,0.02,3,45);
				//SetShotDataA(0,210,3,NULL,0,0,0,45);
				FireShot(0);
		//CreateShot01(Obj_GetX(obj),Obj_GetY(obj),3,atan2(GetY-Obj_GetY(obj),GetX-Obj_GetX(obj)),45,0);
			wait(2);
		}
	}
}

}

#include_function ".\..\txt\data.txt"
#include_function ".\..\lib/lib_anime_Aya.txt"
}

script_enemy Familiar {
    let csd     = GetCurrentScriptDirectory;
	let num = GetArgument;
    @Initialize {
	SetCoordinateType(COODINATE_TYPE_PARENT);
	let num = GetArgument;
        SetLife(600);
        SetDamageRateEx(100,100,0,0);
	TMain;
    }

    @MainLoop {
        SetCollisionA(GetX, GetY, 36);
        MSDSetCollisionB(GetX, GetY, 12);
        yield;
    }

    @DrawLoop {
      //  DrawGraphic(GetX, GetY);
    }

        @Finalize
        {
	MagicCircleBreak(GetX,GetY,10,0.3);
	if(GetCommonDataDefault("BossLife",0)>0)
	{
		loop(5)
		{
		FinalizeItemSet(1);
		}
	}
        }

    task TMain {
        yield;
	GetDamege;
	OutDamageRateZero;
	ZakoEnemyLifeDisplay;
	move;
	alternative(GetCommonDataDefault("SELECTEDDIFFICULT","None"))
	case("Moderate")
	{
	shotM;
	}
	case("Extream")
	{
	shotE;
	}
	case("Apocalypse")
	{
	shotA;
	}
	ZakoEffect(255,0,0);
    }

task move
{
	SetMovePosition02(100*num, 0, 30);
	wait(30);
	let X=100*num;
	let Y=0;
	loop(390)
	{
	yield;
	}
	SetAngle(270);
	let speed=0;
	loop
	{
		SetSpeed(speed);
		speed+=0.1;
		yield;
		if(GetY<GetClipMinY-32){VanishEnemy;}
	}

}

task shotM
{
wait(60);
let speed=4;
loop(5)
{
	let angle=GetAngleToPlayer+rand(-6,6);
	ascent(i in -3..4)
	{
		CreateShot01(GetX,GetY,speed,angle+i*12,9,5);
		CreateShot01(GetX,GetY,speed,angle+i*12+180,9,5);
		CreateShot01(GetX,GetY,speed,angle+i*12,9,8);
		CreateShot01(GetX,GetY,speed,angle+i*12+180,9,8);
		CreateShot01(GetX,GetY,speed,angle+i*12,9,11);
		CreateShot01(GetX,GetY,speed,angle+i*12+180,9,11);
		wait(2);
	}
	speed+=0.2;
	wait(16);
	ascent(i in -3..4)
	{
		CreateShot01(GetX,GetY,speed,angle-i*12,9,5);
		CreateShot01(GetX,GetY,speed,angle-i*12+180,9,5);
		CreateShot01(GetX,GetY,speed,angle-i*12,9,8);
		CreateShot01(GetX,GetY,speed,angle-i*12+180,9,8);
		CreateShot01(GetX,GetY,speed,angle-i*12,9,11);
		CreateShot01(GetX,GetY,speed,angle-i*12+180,9,11);
		wait(2);
	}
	speed+=0.3;
	wait(16);
}

}
/////////////////////////////////////////////////////////
task shotE
{
wait(60);
let speed=3.5;
let angle=rand(0,360);
loop(20)
{
	ascent(i in 0..6)
	{
		Shot1(GetX,GetY,speed,angle+i*60,9,86,5);
	}
angle+=rand(15,20)*num;
speed+=0.2;
wait(15);
}


			function Shot1(let sx,let sy,let speed,let angle,let wide,let gra,let delay)
			{
				let way=9;
				ascent(i in -(way-1)/2..(way+1)/2)
				{
					CreateShot01(sx,sy,speed/((1.05)^absolute(i)),angle+wide/(way-1)*i,gra,delay);
				}
			}

}
////////////////////////////////////////////////////////////
task shotA
{
wait(60);

shot1;

task shot1
{
	let speed=4;
	let angle=rand(0,360);
	let anglePlus=0;
	let anglePlusTheta=90;

loop(42)
{
	ascent(i in 0..12)
	{
	CreateShotA(0,GetX,GetY,0);
	SetShotDataA(0,0,speed,angle+i*30,anglePlus,0,0,45);
	FireShot(0);
	}
	angle+=3;
	anglePlus=0.5*cos(anglePlusTheta);
	anglePlusTheta+=18;
	wait(7);
}
}

}

#include_function ".\..\txt/StageEnemydata.txt"
}

#include_script ".\..\txt/EnemyShotData.txt"
